<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <btn>{{content}}</btn>
            <button 
                v-for="(item,index) in list" 
                @click="handleClick(item.title)"
            >
                {{item.title}}
            </button>
        </div>
        <template id="btn">
            <div>
                <button><slot></slot></button>
            </div>
        </template>
        <script src="../vue.js"></script>
        <script>
            let btn = {
                template: '#btn',
            };
            new Vue({
                el: '#app',
                components: {
                    btn,
                },
                data() {
                    return {
                        content: '默认',
                        list: [
                            { title: '默认', fun: 'toChild1', className: 'default' },
                            { title: '成功', fun: 'toChild2', className: 'success' },
                            { title: '警告', fun: 'toChild3', className: 'warning' },
                        ],
                    };
                },
                methods: {
                    handleClick(type) {
                        if (type === '默认') {
                            // do something
                            this.content = type;
                        } else if (type === '成功') {
                            this.content = type;
                        } else if (type === '警告') {
                            this.content = type;
                        }
                        console.log(type);
                    },
                    toChild1() {
                        console.log(1);
                    },
                    toChild2() {
                        console.log(2);
                    },
                    toChild3() {
                        console.log(3);
                    },
                },
            });

            // ``: 模板字符串
            let st = `world`;
            let str = 'hello';
            let str2 = `h
            e
            l
            l
            o${st}`;
            console.log(str);
            console.log(str2);
        </script>
    </body>
</html>
